﻿using System;
using System.Windows.Forms;
using ApplicationGenerator.DataAccess;
using ApplicationGenerator.GeneratorMenu.BusinessLogic;
using ApplicationGenerator.GeneratorMenu.Forms;
using WeifenLuo.WinFormsUI.Docking;

namespace GUserInterface
{
    public partial class MenuVEPanel : DockContent
    {
        private ApplicationMenuControl applicationMenuControl1;

        public MenuVEPanel()
        {
            InitializeComponent();
            applicationMenuControl1 = new ApplicationMenuControl();
            this.panel1.Controls.Add(applicationMenuControl1);
            applicationMenuControl1.Dock = DockStyle.Fill;
        }

        public MenuVEPanel( ApplicationMenu menu )
        {
            InitializeComponent();
            applicationMenuControl1 = new ApplicationMenuControl(menu);
            this.panel1.Controls.Add(applicationMenuControl1);
            applicationMenuControl1.Dock = DockStyle.Fill;
        }

        public ApplicationMenu getMenu()
        {
            return applicationMenuControl1.GetMenu();
        }


        private void button1_Click(object sender, EventArgs e)
        {
            Guid id = Guid.NewGuid();

            //try to save or update
            if (false == Serializer.Serialize(Policy.Menu, this.applicationMenuControl1.GetMenu(), id, "Menu"))
            {
                Serializer.Update(Policy.Menu, this.applicationMenuControl1.GetMenu(), "Menu");
            }
            
            this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
